<script setup>
// import { onMounted, reactive } from 'vue';
import { isMobile } from '@u/tool'

const coords = reactive({
    latitude:'',
    longitude:''
})
let address = '武汉东湖风景区'

function getPosition () {
  return new Promise((resolve, reject) => {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function (position) {
        let latitude = position.coords.latitude
        let longitude = position.coords.longitude
        let data = {
          latitude: latitude,
          longitude: longitude
        }
        resolve(data)
      }, function () {
        reject(arguments)
      })
    } else {
      reject('你的浏览器不支持当前地理位置信息获取')
    }
  })
}

const Position = () => {
   // 获取当前经纬度坐标
   getPosition().then(result => {
        let queryData = {
            longtitude: String(result.longitude).match(/\d+\.\d{0,6}/)[0],
            latitude: String(result.latitude).match(/\d+\.\d{0,6}/)[0],
            channelType: '00'
        }
        console.log(queryData)
        coords.latitude =   queryData.latitude
        coords.longitude = queryData.longtitude
    }).catch(err => {
      console.error(err)
    })
}

onMounted(()=>{
   
    console.log(navigator.geolocation)
    // checkAmapInstalled()
})
</script>

<template>
 <h1>当前经纬度是</h1>
 <button @click="Position">获取</button>
 <h2>{{ coords.latitude }}</h2>
 <h2>{{  coords.longitude }}</h2>
 <a :href="`https://uri.amap.com/navigation?from=${coords.longitude},${coords.latitude}&to=114.41397,30.549509,${address}&mode=bus&policy=0&src=&coordinate=&callnative=0`"
   target="_blank"> {{address}}</a>
   <br>
   <!-- <h2>高德</h2> -->

   <!-- <a :href="`amapuri://route/plan/?sid=&did=&dlat=30.549509&dlon=114.41397&dname=${address}&dev=0&t=1`">{{address}} ————安卓</a>、 -->
   <!-- <br> -->
   <!-- <a :href="`iosamap://path?sid=&did=&dlat=30.549509&dlon=114.41397&dname=${address}&dev=0&t=1`">{{address}} ————IOS</a> -->

   <!-- <h2>百度</h2>
   <a :href="`bdapp://map/direction?origin=&destination=name:${address}|latlng:30.549509,114.41397&coord_type=bd09ll&mode=transit&src=ios.baidu.openAPIdemo`">
    {{address}} ————安卓
  </a>
  <a href="bdapp://map/direction?origin=&destination=name:北京市丰台区北京西站|latlng:30.549509,114.41397&coord_type=bd09ll&mode=transit&src=ios.baidu.openAPIdemo">百度安卓</a>

  <a href="baidumap://map/direction?origin=&destination=name:北京市丰台区北京西站latlng:30.549509,114.41397&coord_type=bd09ll&mode=transit&src=ios.baidu.openAPIdemo">百度IOS</a>

  <h2>腾讯</h2>
  <a :href="`qqmap://map/routeplan?fromcoord=CurrentLocation&type=bus&to=${address}&tocoord=30.549509,114.41397&policy=2&referer=yunjiaHUD`">腾讯IOS/安卓</a> -->

</template>